export default {

    namespaced: true,

    state: {
        carts:[],
        cartsNum:0
    },
    getters: {

    },
    mutations: {
        setCartsBuyNum(state){
            state.cartsNum++
        },
        setCarts(state,data){
            state.carts = data
        }
    },
    actions: {
        setCarts(context){
            //发送异步请求
            let resData = [
                { id : 1, title : '张一', price : 1.21},
                { id : 2, title : '张儿', price : 1.22},
                { id : 3, title : '张三', price : 1.23},
                { id : 4, title : '张四', price : 1.24}
            ]
            //触发mutations -> 更新数据
            context.commit('setCarts',resData)
        }
    }
}